package com.hongying.config;

import com.hongying.constant.RabbitMqConstant;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {

    @Bean
    public Queue queue(){
        return  new Queue(RabbitMqConstant.HELLO_QUEUE);
    }

    @Bean
    public Queue directQueue(){
        return  new Queue(RabbitMqConstant.DIRECT_QUEUE);
    }

    @Bean
    public Queue baiduQueue(){
        return new Queue(RabbitMqConstant.BAIDU_QUEUE);
    }

    @Bean
    public Queue googleQueue(){
        return new Queue(RabbitMqConstant.GOOGLE_QUEUE);
    }

    @Bean
    public FanoutExchange fanoutExchange(){
        return new FanoutExchange(RabbitMqConstant.FANOUT_EXCHANGE);
    }

    @Bean
    public Binding bindingExchangeBaiduQueue(Queue baiduQueue,FanoutExchange fanoutExchange){
        return BindingBuilder.bind(baiduQueue).to(fanoutExchange);
    }

    @Bean
    public Binding bindingExchangeGoogleQueue(Queue googleQueue,FanoutExchange fanoutExchange){
        return BindingBuilder.bind(googleQueue).to(fanoutExchange);
    }


    @Bean
    public DirectExchange directExchange(){
        return  new DirectExchange(RabbitMqConstant.DIRECT_EXCHANGE);
    }

    @Bean
    public Binding bindingExchangeQueue(Queue directQueue,DirectExchange directExchange){
        return BindingBuilder.bind(directQueue).to(directExchange).with(RabbitMqConstant.DIRECT_ROUTING_KEY);
    }


    @Bean
    public Queue queueMessage(){
        return new Queue(RabbitMqConstant.MESSAGE);
    }

    @Bean
    public Queue queueMessages(){
        return new Queue(RabbitMqConstant.MESSAGES);
    }
    @Bean
    public Queue queueYmq(){
        return new Queue(RabbitMqConstant.YMQ);
    }

    @Bean
    public TopicExchange topicExchange(){
        return new TopicExchange(RabbitMqConstant.TOPIC_EXCHANGE);
    }

    @Bean
    public Binding bindingExchangeMessage(Queue queueMessage,TopicExchange topicExchange){
        return BindingBuilder.bind(queueMessage).to(topicExchange).with(RabbitMqConstant.MESSAGE);
    }

    @Bean
    public Binding bindingExchangeMessages(Queue queueMessages,TopicExchange topicExchange){
        return BindingBuilder.bind(queueMessages).to(topicExchange).with("topic.message.#");
    }


    @Bean
    public Binding bindingExchangeYmq(Queue queueYmq,TopicExchange topicExchange){
        return BindingBuilder.bind(queueYmq).to(topicExchange).with("topic.#");
    }




}
